package cn.edu.cxcyzx.service.impl;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.edu.cxcyzx.entity.MemberPOJO;
import cn.edu.cxcyzx.entity.Project;
import cn.edu.cxcyzx.entity.ProjectCheck;
import cn.edu.cxcyzx.entity.ProjectInfo;
import cn.edu.cxcyzx.entity.ProjectPOJO;
import cn.edu.cxcyzx.service.ProjectService;
import cn.edu.cxcyzx.supervisor.DaoFit;
import cn.edu.cxcyzx.supervisor.ResultDo;

@Service("ProjectService")
public class ProjectServiceImpl implements ProjectService {
	
	@Resource
	public DaoFit daoFit;
	
	@Override
	public ResultDo<List<ProjectInfo>> getAllPro() {
		// TODO Auto-generated method stub
		ResultDo<List<ProjectInfo>> resultDo=new ResultDo<List<ProjectInfo>>();
		List<ProjectInfo> list=daoFit.getProjectDao().getAllPro();
		
		if(list!=null){
			System.out.println("pros.size:"+list.size());
			resultDo.setResult(list);
			resultDo.setSuccess(true);
		}else{
			resultDo.setSuccess(false);
		}
		return resultDo;
	}

	@Override
	public ResultDo<ProjectInfo> getProjectInfo(int projectId) {
		// TODO Auto-generated method stub
		ResultDo<ProjectInfo> resultDo=new ResultDo<ProjectInfo>();
		ProjectInfo projectInfo=daoFit.getProjectDao().getProjectInfo(projectId);
		if(projectInfo!=null&&projectInfo.getProject()!=null){
			resultDo.setSuccess(true);
			resultDo.setResult(projectInfo);
		}else{
			resultDo.setSuccess(false);
		}
		
		return resultDo;
	}
	
	/**
	 * 查询判断文件是否已经上传
	 */
	@Override
	public String isUpload_analyseReport(int projectId) {
		// TODO Auto-generated method stub

		String analyseReport=daoFit.getProjectDao().getAnalyseReport(projectId);
		System.out.println("analyseReport:"+analyseReport);
		
		return analyseReport;
	}

	@Override
	public void update_finishTime(Date update_finishTime, int projectId) {
		// TODO Auto-generated method stub
		if(update_finishTime!=null){
			daoFit.getProjectDao().update_finishTime(update_finishTime, projectId);
		}
	}

	@Override
	public String isUpload_projectReport(int projectId) {
		// TODO Auto-generated method stub
		return daoFit.getProjectDao().getProjectReport(projectId);
	}

	@Override
	public ResultDo<List<MemberPOJO>> getMembersInfo(String leaderId) {
		// TODO Auto-generated method stub
		ResultDo<List<MemberPOJO>> resultDo=new ResultDo<>();
		List<MemberPOJO> memberPOJO=daoFit.getProjectDao().getMemberBy_leaderId(leaderId);
		
		if(memberPOJO!=null){
			System.out.println("memberPOJO.size:"+memberPOJO.size());
			resultDo.setSuccess(true);
			resultDo.setResult(memberPOJO);
		}else{
			resultDo.setSuccess(false);
		}
		return resultDo;
	}

	@Override
	public List<ProjectPOJO> getDalayPro() {
		// TODO Auto-generated method stub
		
		return daoFit.getProjectDao().getDalayPro();
	}

	@Override
	public ResultDo<List<ProjectInfo>> getProgressPro() {
		// TODO Auto-generated method stub
		ResultDo<List<ProjectInfo>> resultDo=new ResultDo<>();
		List<ProjectInfo> list=daoFit.getProjectDao().getProgressPro();
		System.out.println("list.size:"+list.size());
		if(list!=null&&list.size()>0){
			resultDo.setResult(list);
			resultDo.setSuccess(true);
		}else{
			resultDo.setSuccess(false);
		}
		return resultDo;
	}

	@Override
	public ResultDo<List<Project>> getPro_going(String check_date) {
		// TODO Auto-generated method stub
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		Date date=null;
		try {
			date = (Date) format.parse(check_date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("date:"+date);
		ResultDo<List<Project>> resultDo=new ResultDo<>();
		//查询已经提交需求分析（录入项目成员）的项目
		List<Project> list=daoFit.getProjectDao().getCheckPro(date);
		if(list!=null&&list.size()>0){
			resultDo.setResult(list);
			resultDo.setSuccess(true);
		}else{
			resultDo.setSuccess(false);
		}
		return resultDo;
	}

	@Override
	public Date getMin_analyseDate() {
		// TODO Auto-generated method stub
		return daoFit.getProjectDao().getMin_analyseDate();
	}

}
